/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import common.Articulo;
import common.ItemTabla;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import model.Model;
import tiendagui.internal.JInternalFrameImpl;

/**
 *
 * @author Jhonny
 */
public abstract  class Controller {
    protected JInternalFrameImpl            dialog;
    protected Model                         model;


    public Controller(JInternalFrameImpl dialog,Model model) {
        this.dialog = dialog;
        this.model = model;
    }
    public Controller() {
    }
    public abstract  void initComponentView()throws FileNotFoundException,IOException;
    public void cerrar(){
        dialog.setVisible(false);
    }
    protected  void initDatosTablaArticulos(JTable table, List<Articulo> articulos){
        if(articulos!=null){
            List<ItemTabla> list = new LinkedList<ItemTabla>();
            articulos.addAll(articulos);
            initDatosTabla(table, list);
        }
    }
    protected  void initDatosTabla(JTable table, List<ItemTabla> articulos){
        deleteTable(table);
        if(articulos!=null){
            for (ItemTabla itemTabla : articulos) {
                ((DefaultTableModel)table.getModel()).addRow(itemTabla.toVector());
            }
        }
    }
    private void deleteTable(JTable table){
        int countRow = ((DefaultTableModel)table.getModel()).getRowCount();
        for (int i = 0; i < countRow; i++) {
            ((DefaultTableModel)table.getModel()).removeRow(0);
        }
    }

   

    
}
